home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / PowerMacOberon feb96 / Source / KeplerLinks.Mod (.txt) < prev    next >
Encoding:
Oberon Text  |  1995-08-03  |  8.6 KB  |  231 lines  |  [TEXT/.Ob4]

  1. Syntax10.Scn.Fnt
  2. StampElems
  3. Alloc
  4. 3 Aug 95
  5. Syntax10b.Scn.Fnt
  6. Syntax10i.Scn.Fnt
  7. FoldElems
  8. Syntax10.Scn.Fnt
  9. BEGIN
  10.     t.Read^(r); Files.ReadNum(r, t.n)
  11. END Read;
  12. Syntax10.Scn.Fnt
  13. BEGIN
  14.     t.Write^(r); Files.WriteNum(r, t.n)
  15. END Write;
  16. Syntax10.Scn.Fnt
  17. BEGIN
  18.     b.Read^(r); Files.ReadNum(r, b.key)
  19. END Read;
  20. Syntax10.Scn.Fnt
  21. BEGIN
  22.     b.Write^(r); Files.WriteNum(r, b.key)
  23. END Write;
  24. Syntax10.Scn.Fnt
  25.     VAR a, b, c, d, u, v, z, x, y, w, h, i: INTEGER;
  26. BEGIN
  27.     IF but.cmd = "^" THEN
  28.         x := but.p[0].x; IF but.p[1].x < x THEN x := but.p[1].x END;
  29.         y := but.p[0].y; IF but.p[1].y < y THEN y := but.p[1].y END;
  30.         w := ABS(but.p[1].x - but.p[0].x); h := ABS(but.p[0].y - but.p[1].y);
  31.         i := w DIV 5; a := x + i; b := a + i; d := x + w - i; c := d - i;
  32.         i := h DIV 6; u := y + i; v := y + 3*i; z := y + h - i;
  33.         p.DrawLine(b, u, c, u, Display.white, Display.replace);
  34.         p.DrawLine(c, u, c, v, Display.white, Display.replace);
  35.         p.DrawLine(c, v, d, v, Display.white, Display.replace);
  36.         p.DrawLine(d, v, (b+c) DIV 2, z, Display.white, Display.replace);
  37.         p.DrawLine(a, v, (b+c) DIV 2, z, Display.white, Display.replace);
  38.         p.DrawLine(a, v, b, v, Display.white, Display.replace);
  39.         p.DrawLine(b, v, b, u, Display.white, Display.replace)
  40. END Draw;
  41. Syntax10.Scn.Fnt
  42. BEGIN
  43.     IF keys = {MM} THEN
  44.         LinkElems.FollowLink(b.par, b.key, NIL, NIL)
  45.     ELSIF keys = {MM, MR} THEN
  46.         Out.String(b.par); Out.String("  "); Out.Int(b.key, 0); Out.Ln
  47. END Execute;
  48. Syntax10.Scn.Fnt
  49. Syntax10b.Scn.Fnt
  50.     VAR x: INTEGER; s: Texts.Scanner;
  51. BEGIN
  52.     x := 0;
  53.     WHILE x < Display.Width DO
  54.         v := Viewers.This(x, 0);
  55.         WHILE v.state > 1 DO
  56.             IF (v.dsc # NIL) & (v.dsc IS TextFrames.Frame) THEN
  57.                 Texts.OpenScanner(s, v.dsc(TextFrames.Frame).text, 0); Texts.Scan(s);
  58.                 IF s.s = name THEN RETURN END
  59.             END;
  60.             v := Viewers.Next(v)
  61.         END;
  62.         x := x + v.W
  63.     END;
  64.     v := NIL
  65. END GetViewer;
  66. Syntax10.Scn.Fnt
  67.     VAR v: Viewers.Viewer; f: Display.Frame; s: Texts.Scanner; x: INTEGER; 
  68. BEGIN
  69.     x := 0;
  70.     WHILE x < Display.Width DO
  71.         v := Viewers.This(x, 0);
  72.         WHILE v.state > 1 DO
  73.             f := v.dsc.next;
  74.             IF (f # NIL) & (f IS KeplerFrames.Frame) & (f(KeplerFrames.Frame).G = g) THEN
  75.                 Texts.OpenScanner(s, v.dsc(TextFrames.Frame).text, 0); Texts.Scan(s);
  76.                 IF s.class IN {Texts.Name, Texts.String} THEN COPY(s.s, name) ELSE name[0] := 0X END;
  77.                 RETURN
  78.             END;
  79.             v := Viewers.Next(v)
  80.         END;
  81.         x := x + v.W
  82. END GetViewerName;
  83. Syntax10.Scn.Fnt
  84.     VAR v: Viewers.Viewer; f: Display.Frame; s: Texts.Scanner; x: INTEGER; 
  85. BEGIN
  86.     x := 0;
  87.     WHILE x < Display.Width DO
  88.         v := Viewers.This(x, 0);
  89.         WHILE v.state > 1 DO
  90.             f := v.dsc.next;
  91.             IF (f # NIL) & (f IS TextFrames.Frame) & (f(TextFrames.Frame).text = t) THEN
  92.                 Texts.OpenScanner(s, v.dsc(TextFrames.Frame).text, 0); Texts.Scan(s);
  93.                 IF s.class IN {Texts.Name, Texts.String} THEN COPY(s.s, name) ELSE name[0] := 0X END;
  94.                 RETURN
  95.             END;
  96.             v := Viewers.Next(v)
  97.         END;
  98.         x := x + v.W
  99. END GetTextViewerName;
  100. Syntax10.Scn.Fnt
  101. Syntax10b.Scn.Fnt
  102.     VAR v: Viewers.Viewer; g: KeplerGraphs.Graph; f: KeplerFrames.Frame; x, y: INTEGER; c: KeplerGraphs.Constellation; i: INTEGER;
  103. BEGIN
  104.     GetViewer(file, v);
  105.     IF v = NIL THEN
  106.         g := KeplerGraphs.Old(file);
  107.         IF g = NIL THEN NEW(g) END;
  108.         f := KeplerFrames.New(g);
  109.         Oberon.AllocateUserViewer(Oberon.Mouse.X, x, y);
  110.         v := MenuViewers.New(TextFrames.NewMenu(file, keplerMenu), f, TextFrames.menuH, x, y)
  111.     ELSE f := v.dsc.next(KeplerFrames.Frame)
  112.     END;
  113.     g := f.G; f.Neutralize;
  114.     c := g.cons;
  115.     WHILE c # NIL DO
  116.         IF (c IS Target) & (c(Target).n = key) THEN
  117.             FOR i := 0 TO c.nofpts-1 DO
  118.                 IF ~c.p[i].sel THEN g.FlipSelection(c.p[i]) END
  119.             END;
  120.             RETURN
  121.         END;
  122.         c := c.next
  123.     END;
  124. END FollowLink;
  125. Syntax10.Scn.Fnt
  126.     VAR e1: LinkElem;
  127. BEGIN
  128.     WITH e: LinkElem DO
  129.         WITH m: Texts.CopyMsg DO
  130.             IF m.e = NIL THEN NEW(e1); m.e := e1 END;
  131.             LinkElems.Handle(e, m)
  132.         |m: Texts.IdentifyMsg DO
  133.             m.mod := "KeplerLinks"; m.proc := "Alloc"
  134.         | m: LinkElems.FollowMsg DO
  135.             FollowLink(e.file, e.key)
  136.         ELSE LinkElems.Handle(e, m)
  137.         END
  138. END LinkHandler;
  139. Syntax10.Scn.Fnt
  140.     VAR e: LinkElem;
  141. BEGIN
  142.     NEW(e); e.handle := LinkHandler; Texts.new := e
  143. END Alloc;
  144. Syntax10.Scn.Fnt
  145. Syntax10i.Scn.Fnt
  146.     VAR g: KeplerGraphs.Graph; c, sel: KeplerGraphs.Constellation; targ: Target; i: INTEGER; m: TextFrames.InsertElemMsg;
  147.         name: ARRAY 32 OF CHAR; link: LinkElem;
  148. BEGIN
  149.     g := KeplerFrames.Focus;
  150.     (*--- find selected constellation*)
  151.     c := g.cons; sel := NIL;
  152.     WHILE (c # NIL) & (sel = NIL) DO
  153.         IF c.State() > 0 THEN sel := c END;
  154.         c := c.next
  155.     END;
  156.     IF sel = NIL THEN Out.String("-- no constellation selected$"); RETURN END;
  157.     (*--- allocate target constellation*)
  158.     NEW(targ); targ.n := Oberon.Time();
  159.     targ.nofpts := sel.nofpts;
  160.     FOR i := 0 TO sel.nofpts-1 DO targ.p[i] := sel.p[i]; INC(targ.p[i].refcnt) END;
  161.     g.Append(targ);
  162.     (*--- create link element*)
  163.     NEW(link); link.W := 10 * pixel; link.H := 11 * pixel; link.handle := LinkHandler; GetViewerName(g, link.file); link.key := targ.n;
  164.     m.e := link; Viewers.Broadcast(m);
  165. END TextToGraphics;
  166. Syntax10.Scn.Fnt
  167.     VAR link: LinkButton; mark: MarkElems.Elem; t: Texts.Text; beg, end, time: LONGINT; r: Texts.Reader; ch: CHAR;
  168.         g: KeplerGraphs.Graph; s: ARRAY 32 OF CHAR;
  169. BEGIN
  170.     Oberon.GetSelection(t, beg, end, time);
  171.     IF KeplerFrames.nofpts >= 2 THEN
  172.         IF time > 0 THEN
  173.             g := KeplerFrames.Focus;
  174.             NEW(link); link.nofpts := 2;
  175.             KeplerFrames.ConsumePoint(link.p[0]); KeplerFrames.ConsumePoint(link.p[1]);
  176.             In.Open; In.Name(s);
  177.             IF In.Done & (s = "arrow") THEN link.cmd := "^" END;
  178.             GetTextViewerName(t, link.par);
  179.             Texts.OpenReader(r, t, beg); Texts.Read(r, ch);
  180.             IF (ch = Texts.ElemChar) & (r.elem IS MarkElems.Elem) THEN
  181.                 link.key := r.elem(MarkElems.Elem).key
  182.             ELSE
  183.                 mark := MarkElems.New(); link.key := mark.key;
  184.                 Texts.WriteElem(w, mark); Texts.Insert(t, beg, w.buf)
  185.             END;
  186.             g.Append(link)
  187.         ELSE Out.String("-- no target point selected$")
  188.         END
  189.     ELSE Out.String("-- 2 focus points required$")
  190. END GraphicsToText;
  191. MODULE KeplerLinks;    (* HM 
  192. IMPORT Display, Files, Viewers, Texts, TextFrames, MenuViewers, Oberon,
  193.     KeplerPorts, KeplerGraphs, KeplerFrames, LinkElems, MarkElems, In, Out;
  194. CONST
  195.     ML = 2; MM = 1; MR = 0;
  196.     pixel = LONG(10000);
  197.     keplerMenu = "System.Close  System.Copy  System.Grow  Kepler.Store ";
  198.     LinkElem* = POINTER TO LinkDesc;
  199.     LinkDesc* = RECORD (LinkElems.ElemDesc) END;
  200.     Target* = POINTER TO TargetDesc;
  201.     TargetDesc* = RECORD (KeplerGraphs.ConsDesc)
  202.         n*: LONGINT
  203.     END;
  204.     LinkButton = POINTER TO LinkButtonDesc;
  205.     LinkButtonDesc = RECORD (KeplerFrames.ButtonDesc)
  206.         (*field par is used for the file name*)
  207.         key: LONGINT
  208.     END;
  209.     w: Texts.Writer;
  210. (*---------- Target methods ----------*)
  211. PROCEDURE (t: Target) Read* (VAR r: Files.Rider);    
  212. PROCEDURE (t: Target) Write* (VAR r: Files.Rider);    
  213. (*---------- LinkButton methods ----------*)
  214. PROCEDURE (b: LinkButton) Read* (VAR r: Files.Rider);    
  215. PROCEDURE (b: LinkButton) Write* (VAR r: Files.Rider);    
  216. PROCEDURE (but: LinkButton) Draw* (p: KeplerPorts.Port);    
  217. PROCEDURE (b: LinkButton) Execute* (keys: SET);    
  218. (*---------- Auxiliaries ----------*)
  219. PROCEDURE GetViewer (name: ARRAY OF CHAR; VAR v: Viewers.Viewer);    
  220. PROCEDURE GetViewerName (g: KeplerGraphs.Graph; VAR name: ARRAY OF CHAR);    
  221. PROCEDURE GetTextViewerName (t: Texts.Text; VAR name: ARRAY OF CHAR);    
  222. PROCEDURE FollowLink (file: ARRAY OF CHAR; key: LONGINT);    
  223. PROCEDURE LinkHandler* (e: Texts.Elem; VAR m: Texts.ElemMsg);    
  224. (*---------- Commands ----------*)
  225. PROCEDURE Alloc*;    
  226. PROCEDURE TextToGraphics*;    
  227. PROCEDURE GraphicsToText*;    
  228. BEGIN
  229.     Texts.OpenWriter(w)
  230. END KeplerLinks.
  231.